package cn.gx.demo.controller;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.gx.kevin.common.ui.AdminControllerHelper;
import org.redisson.api.RedissonClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.gx.kevin.common.ui.AjaxResult;
import cn.gx.kevin.common.annotation.ApiDescript;
import cn.gx.kevin.common.annotation.ApiParams;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gx.kevin.controller.ResetfulBaseController;
import cn.gx.kevin.service.IBaseService;
import cn.gx.demo.domain.FlowRule;
import cn.gx.demo.service.IFlowRuleService;

/**
*Generate by Kevin's CodeBuilder  2022-01-11 04:05
**/
@ApiDescript("规则表") 
@Controller 
@RequestMapping(value="/flowrule")
public class FlowRuleController extends ResetfulBaseController<FlowRule, String> {

	IFlowRuleService  flowRuleService; 

	@Resource(name="flowRuleService") 
	@Override 
	public void setService(IBaseService<FlowRule, String> service) {
		this.service = service;
		flowRuleService = (IFlowRuleService)service;
	}


	/****生成默认的CURD API，如不需要请删除，上传下载，xls导入导出请自行重写实现*****/

	@Override
	@ApiDescript("Get方式，负责页面请求,如:http://127.0.0.1/web/ctrl/page/[PageName]")
	@RequestMapping(value ="/page/{pageName}", method = RequestMethod.GET)
	public String page(@PathVariable("pageName") String pageName, HttpServletRequest request) throws Exception {
		return super.page(pageName, request);
	}

	/***设置页面模块的子路径****/
	@Override
	public String setPageModelPath(HttpServletRequest request) {
		return "demo" + File.separator + entityPath;
	}

	/***设置datagrid的模块路径,默认base文件夹模块****/
	@Override
	public String setGridModelPath(HttpServletRequest request) {
		return "demo" + File.separator;
	}

	@ApiDescript("新增")
	@Override
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public @ResponseBody AjaxResult add(HttpServletRequest request) throws Exception {
		return super.add(request);
	}

	@ApiDescript("更新")
	@Override
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public @ResponseBody AjaxResult update(HttpServletRequest request) throws Exception {
		return super.update(request);
	}

	/*****保存前拦截，返回空则执行保存，否则返回对应的提示信息*******/
	@Override
	public String saveFilter(FlowRule bean, boolean isupdate, HttpServletRequest request) {
		return super.saveFilter(bean, isupdate, request);
	}

	@ApiParams("{'idList':'id1,id2'}")
	@ApiDescript("删除")
	@Override
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public @ResponseBody AjaxResult delete(HttpServletRequest request) throws Exception {
		return super.delete(request);
	}

	/***删除前约束检查，返回空则执行删除，否则返回对应的提示信息****/
	@Override
	protected String checkContraints(List<String> pks,HttpServletRequest request) throws Exception {
		return null;
	}

	@ApiDescript("分页多条件可排序查询")
	@ApiParams("{'page':1,'pageSize':15,'_col_sort_fieldName':'asc'}")
	@Override
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public @ResponseBody AjaxResult list(HttpServletRequest request) throws Exception {
		return super.list(request);
	}

	/***分页多条件查询参数设置****/
	@Override
	public Map<String, Object> setListParams(HttpServletRequest request) {
		Map<String, Object> prMap = new HashMap<String, Object>();
		return prMap;
	}

	@ApiDescript("非分页多条件/排序普通查询")
	@ApiParams("{}")
	@Override
	@RequestMapping(value = "/query", method = RequestMethod.POST)
	public @ResponseBody AjaxResult query(HttpServletRequest request) throws Exception {
		return super.query(request);
	}

	/***普通多条件查询参数设置****/
	@Override
	public Map<String, Object> setQueryParams(HttpServletRequest request) {
		Map<String, Object> prMap = new HashMap<String, Object>();
		return prMap;
	}

	@ApiDescript("根据ID查询数据")
	@ApiParams("{'id':''}")
	@Override
	@RequestMapping(value = "/get", method = RequestMethod.POST)
	public @ResponseBody AjaxResult get(String id) throws Exception {
		return super.get(id);
	}


	@ApiDescript("测试redis")
	@RequestMapping(value = "/redis")
	public void getAesKey(HttpServletRequest request, HttpServletResponse response) throws Exception {
		//RedissonClient client = RedisTool.getClient();
		AdminControllerHelper.responseJson(response, 0, "数据成功!", null);
	}

}
